<template>
	<view>
		<comment v-for="(item,index) in commentList" :key="index+'comment'" :title="item.title"
			:describe="item.describe" :time="item.time" :hufuTitle="item.hufuTitle" :imageUrl="item.imageUrl"
			:hufuUrl="item.hufuUrl" @getCompanydata="getCompanydata(index)"></comment>
		<uni-popup ref="popup" type="bottom" round background-color="#ffffff" @close="onClose">
			<view class="popup-title">写评论</view>
						<view class="popup-text">
						 <uni-easyinput type="textarea" v-model="popupvalue" placeholder="请输入内容" :inputBorder="false" ></uni-easyinput>
			</view>
			<view class="btton-popup" @click="release">发布</view></uni-popup>
		<goComment title="去评论" @goPage="getCompanydata"></goComment>

	</view>
</template>

<script setup>
	import comment from "./componts/comment.vue"
	import goComment from "./componts/go-comment.vue"

	import {getXhbCommentByPublishId,saveXhbComment}  from "@/api/mutual-assistance";
	import {
		onMounted,
		ref
	} from "vue";
import { onLoad } from "@dcloudio/uni-app";
	const show = ref(false);
	const listData=ref([])
	const popupvalue=ref("");
	const pid=ref("")
	const publishId=ref(null)
	const commentList = ref([
	])
	const popup=ref()
	function getCompanydata(data) {
		show.value = true
		console.log(popup,'.........')
		popup.value.open()
		// if(listData.value){
		// 	pid.value=listData.value[data].userId
		// 	console.log(pid.value,'1111111')

		// }


	}
	function onClose(event) {
		show.value = false
	}

	function release(){
		console.log(111111,popupvalue.value)
		popup.value.close()
		uni.showToast({
			title:"发布成功",
			duration: 2000
		})

		saveXhbComment({
  "pid": pid.value,
  "publishId": publishId.value,
  "context": popupvalue.value
})
getdata()
	}
	
	function getdata(){
		commentList.value=[]
		getXhbCommentByPublishId(publishId.value).then((res)=>{
			console.log(res.data,'//////')
			listData.value=res.data
			res.data.map((o)=>{
				commentList.value.push({
					imageUrl:o.avatar,
					title:o.enterpriseCollectiveName,
					describe:o.context,
					time:o.createTime
				})
				if(o.children.length>0){
					o.children.map((item)=>{
						commentList.value.push({
							imageUrl:item.avatar,
							title:item.enterpriseCollectiveName,
							describe:o.context,
							time:item.createTime,
							hufuTitle:o.enterpriseCollectiveName,
							hufuUrl:o.avatar
						})
					})
				}

			})

		})
	}
	onLoad((option)=>{

		publishId.value=option.id
		getdata()

	})
</script>

<style scoped lang="less">
	.popup-title {
		font-size: 31rpx;
		width: 100%;
		text-align: center;
		height: 82rpx;
		line-height: 82rpx;
	}
.btton-popup{
	width: 90vw;
	height: 80rpx;
	   background-image:linear-gradient(to right, #FF934C, #FC686F);
	   border-radius: 20rpx;
	   font-size:31rpx ;
	   color: #ffffff;
	   text-align: center;
	   line-height: 80rpx;
	   font-family: "ali-m";
	   margin: 20rpx auto;


}

	.popup-text {
		height: 500rpx;

		.popup-input {
			width: 100%;
			height: 100%;

			.uni-input-placeholder {
				top: 0% !important;
			}
		}

	}
	.go-comment{
		   background-image: linear-gradient(to right,#FF934C,#FC686F  );
		width: 90vw;
		height: 80rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 80rpx;
		color: #ffffff;
		font-size:"ali-m" ;
		font-size: 32rpx;
		position: fixed;
		bottom: 10rpx;
		left: 30rpx;
	}
</style>
